﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace case2_1_hemingyang
{
    internal class Program
    {
        static void Main(string[] args)
        {

            BuyWatermelon();
            //BuyWatermelonAdvanced();
            //findZhaoLiu();
            //SimpleCalculator();
            //CalculatePerimeterAndAreaOfTriangle();




        }
        static void BuyWatermelon()
        {
            int count = 12; //假设买 学号07+5=12 斤西瓜
            double price = 2.3; //单价
            double discount = 0.75; //折扣
            double totalPrice = 0; //总价
            totalPrice = count * price; //总价的算法
            if (totalPrice >= 20)
            {
                totalPrice *= discount; //totalPrice=totalPricediscount
            }
            Console.WriteLine("总共支付：{0}", totalPrice);
            Console.Read();
            //20.7
        }

        static void BuyWatermelonAdvanced()
        {
            int count = 12; //假设买学号07+5=12 斤西瓜
            double price = 2.3; //单价
            double discount = 0.75; //折扣
            double totalPrice = 0; //总价
            totalPrice = count * price; //总价的算法
            double discountNum = (int)(totalPrice / 20);  //包含几个20元
            Console.WriteLine("原价{0}元包含了{1}个20元", totalPrice, discountNum);
            double totalDiscountPrice = 20 * discount * discountNum;
            Console.WriteLine("有折扣金额为{0}", totalDiscountPrice);
            double last = totalPrice - 20 * discountNum;
            double finalPrice = last + totalDiscountPrice;
            Console.WriteLine("总共支付：{0}", finalPrice);
            Console.Read();
        }

        static void findZhaoLiu()
        {
            //string[] users = { "张三", "李四", "王五", "赵六", "田七", "刘八" };

            //string[] users = new string[6];
            //users[0] = "张三";
            //users[1] = "李四";
            //users[2] = "王五";
            //users[3] = "赵六";
            //users[4] = "田七";
            //users[5] = "刘八";

            string[] users = new string[] { "张三", "李四", "王五", "赵六", "田七", "刘八" };

            for (int i = 0; i < users.Length; i++)
            {
                if (users[i] == "赵六")
                {
                    Console.WriteLine("找到赵六啦！！！");
                    Console.Read();
                    break;

                }

            }
        }

        static void SimpleCalculator()
        {
            while (true)
            {


                double a, b, res = 0;
                char operation;
                Console.WriteLine("欢迎使用简单计算器！");
                Console.WriteLine("请输入第一个数字");
                a = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("请输入操作符");
                operation = Convert.ToChar(Console.ReadLine());
                Console.WriteLine("请输入第二个数字");
                b = Convert.ToDouble(Console.ReadLine());


                switch (operation)
                {
                    case '+':
                        res = a + b;
                        break;
                    case '-':
                        res = a - b;
                        break;
                    case '*':
                        res = a * b;
                        break;
                    case '/':
                        {
                            if (a == 0)
                            {
                                Console.WriteLine("除数不能为0");
                                continue;
                            }
                        }
                        res = a / b;
                        break;
                    default:
                        {
                            Console.WriteLine("请输入+-*/合法运算符");
                            continue;

                        }

                }
                Console.WriteLine("{0}{1}{2}的结果是{3}", a, operation, b, res);
                Console.WriteLine("等待用户按Enter键继续");
                Console.ReadLine(); // 等待用户按Enter键继续
            }
        }

        static void CalculatePerimeterAndAreaOfTriangle()
        {

            Console.WriteLine("欢迎使用三角形周长面积计算器！");
            Console.WriteLine("请输入第一条边");
            double a = Convert.ToDouble(Console.ReadLine());
            //double a = 6;
            Console.WriteLine("请输入第二条边");
            double b = Convert.ToDouble(Console.ReadLine());
            //double b = 6;
            Console.WriteLine("请输入第三条边");
            double c = Convert.ToDouble(Console.ReadLine());
            //double c = 6;
            if (a - b < c && a - c < b && b - c < a)
            {
                double perimeter = (a + b + c);
                double cosC = (a * a + b * b - c * c) / (2 * a * b);
                //Console.WriteLine("{0}", cosC);
                double sinC = Math.Sqrt(1 - cosC * cosC);
                //Console.WriteLine("{0}", sinC);
                double area = 0.5 * a * b * sinC;
                Console.WriteLine("三角形周长{0}", perimeter);
                Console.WriteLine("三角形面积{0}", area);
                Console.WriteLine("等待用户按Enter键继续");
                Console.ReadLine(); // 等待用户按Enter键继续
            }
            Console.WriteLine("这不是一个三角形");
            Console.Read();

        }
    }
}
